home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 9 / af009.adf / Devpac V2 / helloworld.s < prev    next >
Text File  |  1987-08-27  |  6KB  |  267 lines

  1. * the 'Hello World' program in 68000 Assembler
  2. * the C version is on page 2-10 of the Intuition manual
  3. * this source code (C) HiSoft 1987 All Rights Reserved
  4.  
  5.     include    intuition/intuition_lib.i
  6.     include    graphics/graphics_lib.i
  7.     include    exec/exec_lib.i
  8.  
  9. * from intuition/intuition.i
  10. CLOSEWINDOW    EQU    $00000200
  11.     rsreset
  12. Window    rs.b    0
  13. wd_NextWindow    rs.l    1
  14. wd_LeftEdge    rs.w    1
  15. wd_TopEdge    rs.w    1
  16. wd_Width    rs.w    1
  17. wd_Height    rs.w    1
  18. wd_MouseY    rs.w    1
  19. wd_MouseX    rs.w    1
  20. wd_MinWidth    rs.w    1
  21. wd_MinHeight    rs.w    1
  22. wd_MaxWidth    rs.w    1
  23. wd_MaxHeight    rs.w    1
  24. wd_Flags    rs.l    1
  25. wd_MenuStrip    rs.l    1
  26. wd_Title    rs.l    1
  27. wd_FirstRequest    rs.l    1
  28. wd_DMRequest    rs.l    1
  29. wd_ReqCount    rs.w    1
  30. wd_WScreen    rs.l    1
  31. wd_RPort    rs.l    1
  32. wd_BorderLeft    rs.b    1
  33. wd_BorderTop    rs.b    1
  34. wd_BorderRight    rs.b    1
  35. wd_BorderBottom    rs.b    1
  36. wd_BorderRPort    rs.l    1
  37. wd_FirstGadget    rs.l    1
  38. wd_Parent    rs.l    1
  39. wd_Descendant    rs.l    1
  40. wd_Pointer    rs.l    1
  41. wd_PtrHeight    rs.b    1
  42. wd_PtrWidth    rs.b    1
  43. wd_XOffset    rs.b    1
  44. wd_YOffset    rs.b    1
  45. wd_IDCMPFlags    rs.l    1
  46. wd_UserPort    rs.l    1
  47. wd_WindowPort    rs.l    1
  48. wd_MessageKey    rs.l    1
  49. wd_DetailPen    rs.b    1
  50. wd_BlockPen    rs.b    1
  51. wd_CheckMark    rs.l    1
  52. wd_ScreenTitle    rs.l    1
  53. wd_GZZMouseX    rs.w    1
  54. wd_GZZMouseY    rs.w    1
  55. wd_GZZWidth    rs.w    1
  56. wd_GZZHeight    rs.w    1
  57. wd_ExtData    rs.l    1
  58. wd_UserData    rs.l    1
  59. wd_WLayer    rs.l    1
  60. IFont    rs.l    1
  61. wd_Size    rs.w    0
  62. WINDOWSIZING    EQU    $0001
  63. WINDOWDRAG    EQU    $0002
  64. WINDOWDEPTH    EQU    $0004
  65. WINDOWCLOSE    EQU    $0008
  66. SMART_REFRESH    EQU    $0000
  67. ACTIVATE    EQU    $1000
  68.     rsreset
  69. NewWindow    rs.b    0
  70. nw_LeftEdge    rs.w    1
  71. nw_TopEdge    rs.w    1
  72. nw_Width    rs.w    1
  73. nw_Height    rs.w    1
  74. nw_DetailPen    rs.b    1
  75. nw_BlockPen    rs.b    1
  76. nw_IDCMPFlags    rs.l    1
  77. nw_Flags    rs.l    1
  78. nw_FirstGadget    rs.l    1
  79. nw_CheckMark    rs.l    1
  80. nw_Title    rs.l    1
  81. nw_Screen    rs.l    1
  82. nw_BitMap    rs.l    1
  83. nw_MinWidth    rs.w    1
  84. nw_MinHeight    rs.w    1
  85. nw_MaxWidth    rs.w    1
  86. nw_MaxHeight    rs.w    1
  87. nw_Type    rs.w    1
  88. nw_SIZE    rs.w    0
  89. CUSTOMSCREEN    EQU    $000F
  90. TOPAZ_SIXTY    EQU    9
  91.  
  92. * from graphics/text.i
  93. FS_NORMAL    EQU    0
  94. FPF_ROMFONT    equ    1<<0
  95.  
  96. * from exec/nodes.i
  97.     rsreset
  98. LN    rs.b    0
  99. LN_SUCC    rs.l    1
  100. LN_PRED    rs.l    1
  101. LN_TYPE    rs.b    1
  102. LN_PRI    rs.b    1
  103. LN_NAME    rs.l    1
  104. LN_SIZE    rs.w    0
  105.  
  106. * from exec/lists.i
  107.     rsreset
  108. LH    rs.b    0
  109. LH_HEAD    rs.l    1
  110. LH_TAIL    rs.l    1
  111. LH_TAILPRED    rs.l    1
  112. LH_TYPE    rs.b    1
  113. LH_pad    rs.b    1
  114. LH_SIZE    rs.w    0
  115.  
  116. * from exec/ports.i
  117.     rsreset
  118. MP    rs.b    LN_SIZE
  119. MP_FLAGS    rs.b    1
  120. MP_SIGBIT    rs.b    1
  121. MP_SIGTASK    rs.l    1
  122. MP_MSGLIST    rs.b    LH_SIZE
  123. MP_SIZE    rs.w    0
  124. MP_SOFTINT    EQU    MP_SIGTASK
  125. PF_ACTION    EQU    3
  126. PA_SIGNAL    EQU    0
  127. PA_SOFTINT    EQU    1
  128. PA_IGNORE    EQU    2
  129.  
  130. INTUITION_REV    equ    31        v1.1
  131. GRAPHICS_REV    equ    31        v1.1
  132.  
  133. * Open the intuition library
  134.  
  135.     moveq    #100,d4            default error return code
  136.  
  137.     moveq    #INTUITION_REV,d0    version
  138.     lea    int_name(pc),a1
  139.     CALLEXEC OpenLibrary
  140.     tst.l    d0
  141.     beq    exit_false        if failed then quit
  142.     move.l    d0,_IntuitionBase    else save the pointer
  143.  
  144.     moveq    #GRAPHICS_REV,d0
  145.     lea    graf_name(pc),a1
  146.     CALLEXEC OpenLibrary
  147.     tst.l    d0
  148.     beq    exit_closeint        if failed then close Int, exit
  149.     move.l    d0,_GfxBase
  150.  
  151.     lea    MyNewScreen(pc),a0
  152.     CALLINT    OpenScreen        open a screen
  153.     tst.l    d0
  154.     beq    exit_closeall        if failed the close both, exit
  155.     move.l    d0,MyScreen
  156.  
  157. * now initialise a NewWindow structure. This is normally easier to
  158. * do with dc.w/dc.l statement etc, but for comparison with the C
  159. * version we do it like this
  160.     lea    MyNewWindow(pc),a0    good place to start
  161.     move.w    #20,nw_LeftEdge(a0)
  162.     move.w    #20,nw_TopEdge(a0)
  163.     move.w    #300,nw_Width(a0)
  164.     move.w    #100,nw_Height(a0)
  165.     move.b    #0,nw_DetailPen(a0)
  166.     move.b    #1,nw_BlockPen(a0)
  167.     move.l    #window_title,nw_Title(a0)
  168. _temp    set    WINDOWCLOSE!SMART_REFRESH!ACTIVATE!WINDOWSIZING
  169.     move.l    #_temp!WINDOWDRAG!WINDOWDEPTH,nw_Flags(a0)
  170.     move.l    #CLOSEWINDOW,nw_IDCMPFlags(a0)
  171.     move.w    #CUSTOMSCREEN,nw_Type(a0)
  172.     clr.l    nw_FirstGadget(a0)
  173.     clr.l    nw_CheckMark(a0)
  174.     move.l    MyScreen(pc),nw_Screen(a0)
  175.     clr.l    nw_BitMap(a0)
  176.     move.w    #100,nw_MinWidth(a0)
  177.     move.w    #25,nw_MinHeight(a0)
  178.     move.w    #640,nw_MaxWidth(a0)
  179.     move.w    #200,nw_MaxHeight(a0)
  180.  
  181. * thats it set up, now open the window (a0=NewWindow already)
  182.     CALLINT    OpenWindow
  183.     tst.l    d0
  184.     beq    exit_closescr            if failed
  185.     move.l    d0,MyWindow            save it
  186.  
  187.     move.l    d0,a1                window
  188.     move.l    wd_RPort(a1),a1            rastport
  189.     moveq    #20,d0                X
  190.     moveq    #20,d1                Y
  191.     CALLGRAF Move                move the cursor
  192.  
  193.     move.l    MyWindow(pc),a0
  194.     move.l    wd_RPort(a0),a1            rastport
  195.     lea    hello_message(pc),a0
  196.     moveq    #11,d0
  197.     CALLGRAF Text                print something
  198.  
  199.     move.l    MyWindow(pc),a0
  200.     move.l    wd_UserPort(a0),a0
  201.     move.b    MP_SIGBIT(a0),d1        (misprint in manual)
  202.     moveq    #0,d0
  203.     bset    d1,d0                do a shift
  204.     CALLEXEC Wait
  205.  
  206.     moveq    #0,d4                return code
  207.  
  208. * various exit routines that do tidying up, given a return code in d4
  209.  
  210.     move.l    MyWindow(pc),a0
  211.     CALLINT CloseWindow
  212.  
  213. exit_closescr
  214.     move.l    MyScreen(pc),a0
  215.     CALLINT CloseScreen
  216.  
  217. exit_closeall
  218.     move.l    _GfxBase(pc),a1
  219.     CALLEXEC CloseLibrary
  220.  
  221. exit_closeint
  222.     move.l    _IntuitionBase(pc),a1
  223.     CALLEXEC CloseLibrary
  224.  
  225. exit_false
  226.     move.l    d4,d0                return code
  227.     rts
  228.  
  229. * the definition of the screen - note that in assembler you
  230. * MUST get the sizes of these fields correct, by consulting either
  231. * the RKM or the header files
  232.  
  233. MyNewScreen    dc.w    0,0        left, top
  234.         dc.w    320,200        width, height
  235.         dc.w    2        depth
  236.         dc.b    0,1        pens
  237.         dc.w    0        viewmodes
  238.         dc.w    CUSTOMSCREEN    type
  239.         dc.l    MyFont        font
  240.         dc.l    screen_title    title
  241.         dc.l    0        gadgets
  242.         dc.l    0        bitmap
  243.  
  244. * my font definition
  245. MyFont    dc.l    font_name
  246.     dc.w    TOPAZ_SIXTY
  247.     dc.b    FS_NORMAL
  248.     dc.b    FPF_ROMFONT
  249.  
  250. * the variables
  251. _IntuitionBase    dc.l    0        Intuition lib pointer
  252. _GfxBase    dc.l    0        graphics lib pointer
  253. MyScreen        dc.l    0
  254. MyWindow        dc.l    0
  255. MyNewWindow    ds.b    nw_SIZE        a buffer
  256.  
  257.  
  258. * some strings
  259. int_name    INTNAME
  260. graf_name    GRAFNAME
  261. hello_message    dc.b    'Hello World'
  262.  
  263. * these are C strings, so have to be null terminated
  264. screen_title    dc.b    'My Own Screen',0
  265. font_name    dc.b    'topaz.font',0
  266. window_title    dc.b    'A Simple Window',0
  267.